#include "bga/graphics/VertexBufferObject.h"


namespace bga
{

VertexBufferObject::VertexBufferObject() : GLObject()
{
    /// generate object id
    this->id = generate();
    this->target = GL_ARRAY_BUFFER_ARB;
    this->mode = GL_STREAM_DRAW;
}

VertexBufferObject::~VertexBufferObject()
{
    glDeleteBuffers(1, &(this->id));
}

void VertexBufferObject::bind() const
{
    glBindBuffer(this->target, this->id);
}

void VertexBufferObject::unbind() const
{
    glBindBuffer(this->target, 0);
}

void VertexBufferObject::allocateBuffer(GLsizei size) const
{
    glBufferData(this->target, (GLsizei)size, NULL, this->mode);
}

void VertexBufferObject::setData(GLint first, GLsizei size, const GLvoid* data) const
{
    glBufferSubData(this->target, first, size, data);
}

void VertexBufferObject::setTarget(GLenum target)
{
    this->target = target;
}

GLenum VertexBufferObject::getTarget() const
{
    return this->target;
}

void VertexBufferObject::setMode(GLenum mode)
{
    this->mode = mode;
}

GLenum VertexBufferObject::getMode() const
{
    return this->mode;
}

GLuint VertexBufferObject::generate() const
{
    GLuint id;
    glGenBuffers(1, &id);
    return id;
}

}

